import { Injectable } from "@angular/core";
import { ActivatedRouteSnapshot, Resolve } from "@angular/router";
import { forkJoin, Observable } from "rxjs";
import { first } from "rxjs/internal/operators";
import { Lyric, Song } from "src/app/services/data-types/common.types";
import { SongService } from "src/app/services/song.service";

type SongDataModel = [Song, Lyric];

@Injectable()
export class SongInfoResolverService implements Resolve<SongDataModel>{
  constructor( private songServe: SongService ){}
  resolve(route: ActivatedRouteSnapshot): Observable<SongDataModel>{
    const id = route.paramMap.get('id');
    return forkJoin([
      this.songServe.getSongDetail(id!),
      this.songServe.getLyric(Number(id))
    ]).pipe(first());
  }
}
